import {
  Updata_AVATAR_URL,
  UPDATE_AVATAR_TEMP_URL,
  UPDATE_NICK_NAME,
  UPDATE_USER_NAME,
  CLEAR_USER_INFO,
} from "../constant";

let initState = {
  avatarUrl: "",
  avatarTempUrl: "",
  nickName: "",
  userName: "",
};
export default function addReducers(preState = initState, action)  {
  const { type, data } = action;
  let state = JSON.parse(JSON.stringify(preState));
  switch (type) {
    case Updata_AVATAR_URL:
      return {
        ...state,
        avatarUrl: data,
      };
    case UPDATE_AVATAR_TEMP_URL:
      return {
        ...state,
        avatarTempUrl: data,
      };
    case UPDATE_NICK_NAME:
      return {
        ...state,
        nickName: data,
      };
    case UPDATE_USER_NAME:
      return {
        ...state,
        userName: data,
      };
      case CLEAR_USER_INFO:
        return initState;
    default:
      return preState;
  }
};
